package com.splant.android.smart.UILevel.Community.fragments;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import com.bumptech.glide.load.resource.bitmap.BitmapTransformation;
import com.splant.android.R;
import com.splant.android.smart.ModelLevel.DetectorListBean;
import com.splant.android.smart.SystemDefinedLevel.LRecyclerview.base.BaseMultiAdapter;
import com.splant.android.smart.SystemDefinedLevel.LRecyclerview.base.SuperViewHolder;

/**
 * Created by Administrator on 2017/8/17.
 */

public class Garden_DetectorList_Device_Adapter extends BaseMultiAdapter<DetectorListBean.Detector> {

    private Context mContext;


    public Garden_DetectorList_Device_Adapter(Context context) {
        super(context);
        mContext = context;
        addItemType(0, R.layout.garden_detectorlist_device_item);
    }

    @Override
    public void onBindItemHolder(SuperViewHolder holder, int position) {

        ImageView img_detector = holder.getView(R.id.img_detector);
        TextView tv_detectorName = holder.getView(R.id.tv_detectorName);
        TextView tv_plantName=holder.getView(R.id.tv_plantName);
        TextView tv_detectorId = holder.getView(R.id.tv_detectorId);
        TextView tv_detectorState = holder.getView(R.id.tv_detectorState);
        TextView tv_detectorStartTime = holder.getView(R.id.tv_detectorStartTime);
        TextView tv_detectorEndTime = holder.getView(R.id.tv_detectorEndTime);
        ImageView img_detectorElectricity = holder.getView(R.id.img_detectorElectricity);
        TextView tv_detectorDbm = holder.getView(R.id.tv_detectorDbm);

        DetectorListBean.Detector detector = getDataList().get(position);

        Glide.with(mContext)
                .load(detector.getPlantImgUrl())
                .dontAnimate()
                .placeholder(R.mipmap.garden_ic_plantimg_fail)
                .into(img_detector);

        tv_detectorName.setText(detector.getDetectorName());
        tv_plantName.setText(detector.getPlantName());
        tv_detectorId.setText(detector.getDetectorId());

        if (detector.getDetectorState() == 1)
        {
            tv_detectorState.setText("在线");
        }
        else if (detector.getDetectorState() == 2)
        {
            tv_detectorState.setText("离线");

        }
        else if (detector.getDetectorState() == 3)
        {
            tv_detectorState.setText("未组网");
        }
        tv_detectorStartTime.setText(detector.getStOnLine());
        tv_detectorEndTime.setText(detector.getEtOnLine());

        if (detector.getElectricity()<0)
            detector.setElectricity(0);

        if (detector.getElectricity()<=25)
        {
            img_detectorElectricity.setImageResource(R.mipmap.garden_ic_electricity_1);
        }
        else if (detector.getElectricity()<=50)
        {
            img_detectorElectricity.setImageResource(R.mipmap.garden_ic_electricity_2);
        }
        else if (detector.getElectricity()<=75)
        {
            img_detectorElectricity.setImageResource(R.mipmap.garden_ic_electricity_3);
        }
        else
        {
            img_detectorElectricity.setImageResource(R.mipmap.garden_ic_electricity_4);
        }

        tv_detectorDbm.setText( String.valueOf(detector.getSignalIntensity()) );

    }
}
